package com.bangcommunity.bbframe.sdm.web.shiro.token;

import com.bangcommunity.bbframe.sdm.web.shiro.ISdmPemissionService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Serializable;

/**
 * @author tanghc
 * @Date 17/11/16
 */
public class SdmTokenAuthorizeFilter<PK extends Serializable> extends AbstractTokenAuthorizeFilter {

    @Autowired(required = false)
    private ISdmPemissionService sdmPemissionService;

    @Override
    protected boolean hasPermition(ServletRequest request, ServletResponse response, String resourceId) throws Exception {
        return sdmPemissionService.hasPermition((HttpServletRequest)request,(HttpServletResponse)response,resourceId);
    }

    @Override
    protected String getResourceId(ServletRequest request, ServletResponse response) {
        return ((HttpServletRequest)request).getRequestURI();
    }

    public ISdmPemissionService getSdmPemissionService() {
        return sdmPemissionService;
    }

    public void setSdmPemissionService(ISdmPemissionService sdmPemissionService) {
        this.sdmPemissionService = sdmPemissionService;
    }
}
